package sd.czw.com.mmgapp.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import sd.czw.com.mmgapp.R;
import sd.czw.com.mmgapp.activity.ShouCangActivity;
import sd.czw.com.mmgapp.activity.TGActivity;
import sd.czw.com.mmgapp.activity.WantToRzActivity;
import sd.czw.com.mmgapp.activity.YHJActivity;
import sd.czw.com.mmgapp.customviews.pulldownview.PullToZoomScrollViewEx;

/**
 * Created by czw
 * desc 描述：
 * on 2017/7/5.
 */
public class PersonalFragment extends Fragment implements View.OnClickListener {

    private View view;
    private View header;
    private View zoom;
    private View contentZoom;
    PullToZoomScrollViewEx ptzsv;
    private ImageView headimage;
    private TextView tv_level;
    private Button btn_vip,btn_sc,btn_yhq,btn_paywait,btn_goodswait,btn_getgoods;
    private LinearLayout rl_seedingdan;
    private LinearLayout user_info,person_money,want_rz,tuiguang,goods_address,kefu,help,aboutour,login_out;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_person,container,false);
        ptzsv = (PullToZoomScrollViewEx) view.findViewById(R.id.ptzsve);
        DisplayMetrics localDisplayMetrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
        int mScreenHeight = localDisplayMetrics.heightPixels;
        int mScreenWidth = localDisplayMetrics.widthPixels;
        LinearLayout.LayoutParams localObject = new LinearLayout.LayoutParams(mScreenWidth, (int) (9.0F * (mScreenWidth / 14.0F)));
        ptzsv.setHeaderLayoutParams(localObject);
        initviews();
        inithead();
        initlist();
        initlistener();
        return view;
    }

    private void initlistener() {

        btn_yhq.setOnClickListener(this);//优惠券
        btn_sc.setOnClickListener(this);//个人收藏

        rl_seedingdan.setOnClickListener(this);//查看订单


        goods_address.setOnClickListener(this);//收货地址

        tuiguang.setOnClickListener(this);
        want_rz.setOnClickListener(this);
    }

    //获取列表控件
    private void initlist() {
        rl_seedingdan = (LinearLayout) contentZoom.findViewById(R.id.l_myorder);//查看订单
        btn_paywait = (Button) contentZoom.findViewById(R.id.btn_paywait);//待付款
        btn_goodswait = (Button) contentZoom.findViewById(R.id.btn_goodswait);//带发货
        btn_getgoods = (Button) contentZoom.findViewById(R.id.btn_getgoods);//待收货
        user_info = (LinearLayout)contentZoom.findViewById(R.id.l_user_info);//用户信息
        person_money = (LinearLayout)contentZoom.findViewById(R.id.l_personal_funds);//个人资金
        want_rz = (LinearLayout)contentZoom.findViewById(R.id.l_iwant_enter);//我要入驻
        tuiguang = (LinearLayout)contentZoom.findViewById(R.id.l_tuiguang);//推广链接
        goods_address = (LinearLayout)contentZoom.findViewById(R.id.l_received_address);//收货地址
        kefu = (LinearLayout)contentZoom.findViewById(R.id.l_kefu);//呼叫客服
        help = (LinearLayout)contentZoom.findViewById(R.id.l_help);//帮助说明
        aboutour = (LinearLayout)contentZoom.findViewById(R.id.l_about);//关于我们
        login_out = (LinearLayout)contentZoom.findViewById(R.id.r_logout);//退出登录
    }

    //获取头部控件
    private void inithead() {
        headimage = (ImageView) header.findViewById(R.id.iv_logo);//头部头像
        tv_level = (TextView) header.findViewById(R.id.tv_level);
        btn_vip = (Button) header.findViewById(R.id.btn_vip);//会员中心
        btn_sc = (Button) header.findViewById(R.id.btn_sc);//个人收藏
        btn_yhq = (Button) header.findViewById(R.id.btn_yhq);//优惠券
        headimage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getContext(), "==智障，别点我", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initviews() {
        header = LayoutInflater.from(getContext()).inflate(R.layout.layout_person_header,null,false);
        zoom = LayoutInflater.from(getContext()).inflate(R.layout.layout_person_zoom,null,false);
        contentZoom = LayoutInflater.from(getContext()).inflate(R.layout.layout_person_list,null,false);
        ptzsv.setHeaderView(header);
        ptzsv.setZoomView(zoom);
        ptzsv.setScrollContentView(contentZoom);
        ptzsv.setParallax(true);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            //优惠券
            case R.id.btn_yhq:
                startOtherActivity(YHJActivity.class);
                break;
            //个人收藏
            case R.id.btn_sc:
                startOtherActivity(ShouCangActivity.class);
                break;
            //查看订单
            case R.id.l_myorder:
                break;

            //我的推广
            case R.id.l_tuiguang:
                startOtherActivity(TGActivity.class);
                break;
            //我要入驻
            case R.id.l_iwant_enter:
                startOtherActivity(WantToRzActivity.class);
                break;

            //收货地址
            case R.id.l_received_address:
                //startOtherActivity();
                break;


        }
    }


    private void startOtherActivity(Class c){
        Intent intent = new Intent(getActivity(),c);
        startActivity(intent);
    }
}
